import React, { FC } from 'react'
import { TableItemWrap } from '../../../../../components'
import { ItemLabel } from './ItemLabel'
import { ItemAction } from './ItemAction'
import { ItemStatus } from './ItemStatus'
import { MccModel } from '../translator'
import { useMccStore } from '@/pages/manager/store'
import { IMcc } from '@/api/manager/type'
import { tableAllItemCheck } from '@/pages/manager/store.combine'
import { useActionButtonsStore } from '../../../actionButtons/store'
import { useParamsStore } from '../../../store'

interface TableItemProps {
	rowData: Omit<MccModel<IMcc>, 'attr' | 'children'>
	isOdd: boolean
	style?: React.CSSProperties
}
export const TableItem: FC<TableItemProps> = ({ rowData, isOdd, style }) => {
	const actions = useActionButtonsStore((state) => state.screenList)
	const flag = actions.includes('hangUp') || actions.includes('delete') // 操作类型
	const handleClick = () => {
		// 观众不可用进入轮询 添加操需判断终端是否是互动终端   删除和挂断接直接操作
		if (rowData.mcc.isMt || (!rowData.mcc.isMt && !rowData.mcc.status.isOnline)) {
			const superMtNum = useMccStore.getState().mccInfo.superMtNum
			if (superMtNum === 1) {
				if ((rowData.mcc.isMt && rowData.mcc.status.isInteractive && !flag) || flag) {
					tableAllItemCheck(rowData)
				}
			} else {
				tableAllItemCheck(rowData)
			}
		}
	}
	const { nameWidth, operateWidth, statusWidth } = useParamsStore((state) => state.tableWidth)
	return (
		<TableItemWrap isOdd={isOdd} onClick={handleClick} style={style}>
			<ItemLabel propWidth={nameWidth} {...rowData} />
			<ItemAction mcc={rowData.mcc} status={rowData.status} propWidth={operateWidth} />
			<ItemStatus mcc={rowData.mcc} propWidth={statusWidth} />
		</TableItemWrap>
	)
}
